package com.xtool.livewallpaper.video

import android.net.Uri
import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.xtool.livewallpaper.base.MainApplication
import kotlinx.coroutines.launch
import java.io.File

class VideoWallpaperViewModel : ViewModel() {
    val mediaPlayer = SystemMediaPlayer().apply {
        setLoop(true)
    }
    var videoPath: Uri? = null
    var loading = MutableLiveData(true)
    var files = MutableLiveData<List<File>>()
    fun init(videoPath: Uri) {
        this.videoPath = videoPath
        viewModelScope.launch() {
            val dir = File("${MainApplication.gContext.filesDir.absolutePath}/wallpapers")
            files.postValue(dir.listFiles()?.toList())
            loading.postValue(false)
        }
    }
}